package com.ems.service.impl.supers.questions;

import com.ems.dao.supers.questions.ShortAnswerDao;
import com.ems.dao.supers.questions.answer.ShortAnswerAnsDao;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.questions.ShortAnswer;
import com.ems.pojo.questions.Subject;
import com.ems.pojo.questions.answer.ShortAnswerAns;
import com.ems.service.supers.questions.ShortAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/27
 * @Description: 描述
 * @Version: 1.0
 */
@Service("shortAnswerService")
public class ShortAnswerServiceImpl implements ShortAnswerService {
    @Autowired
    private ShortAnswerDao shortAnswerDao;

    @Autowired
    private ShortAnswerAnsDao shortAnswerAnsDao;

    private ShortAnswerAns shortAnswerAns;

    @Override
    public void addShortAnswer(List<ShortAnswer> shortAnswers) {
        if(shortAnswers != null && shortAnswers.size() > 0){
            for(int i = 0;i < shortAnswers.size();i ++){
                shortAnswerDao.addShortAnswer(shortAnswers.get(i));
                shortAnswerAns = shortAnswers.get(i).getShortAnswerAns();
                shortAnswerAns.setSa_id(shortAnswers.get(i).getSa_id());
                shortAnswerAnsDao.addShortAnswerAns(shortAnswerAns);
            }
        }
    }

    @Override
    public void deleteShortAnswer(List<ShortAnswer> shortAnswerList) {
        if(shortAnswerList != null){
            for(int i = 0;i < shortAnswerList.size();i ++){
                //删除答案
                shortAnswerAnsDao.deleteShortAnswerAns(shortAnswerList.get(i).getShortAnswerAns().getSaa_id());

                //删除题目
                shortAnswerDao.deleteShortAnswer(shortAnswerList.get(i).getSa_id());

            }
        }
    }

    @Override
    public void updateShortAnswer(ShortAnswer shortAnswer) {
        shortAnswerDao.updateShortAnswer(shortAnswer);
        shortAnswerAnsDao.updateShortAnswer(shortAnswer.getShortAnswerAns());
    }


    @Override
    public List<Subject> findShortAnswer(RequestData requestData) {
        List<Subject> list = shortAnswerDao.findShortAnswer(requestData.getMap());
        return list;
    }
}
